{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8024471faac3a296",
   "metadata": {},
   "source": [
    "# Ionic Shopping Tool\n",
    "\n",
    "[Ionic](https://www.ioniccommerce.com/) is a plug and play ecommerce marketplace for AI Assistants. By using Ionic, you are effortlessly providing your users with the ability to shop and transact directly within your agent, and you'll get a cut of the transaction.\n",
    "\n",
    "This is a basic jupyter notebook demonstrating how to integrate the Ionic Shopping Tool. For more information on setting up your Agent with Ionic, see the Ionic [documentation](https://docs.ioniccommerce.com/introduction).\n",
    "\n",
    "This Jupyter Notebook demonstrates how to use the Ionic tool with an Agent.\n",
    "\n",
    "---\n",
    "\n",
    "## Setup the Tool\n",
    "### First, let's install our dependencies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "856d9803ec1cdd9c",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install llama-index llama-hub ionic-api-sdk"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eedd002505e12801",
   "metadata": {},
   "source": [
    "### Configure OpenAI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ[\"OPENAI_API_KEY\"] = \"sk-api-key\"\n",
    "\n",
    "from llama_index.core.agent.workflow import FunctionAgent\n",
    "from llama_index.llms.openai import OpenAI"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8506dd2f8e36cad4",
   "metadata": {},
   "source": [
    "### Import and configure the Ionic Shopping Tool "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f95ef80d8aa9bd5f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "query\n"
     ]
    }
   ],
   "source": [
    "from llama_hub.tools.ionic_shopping.base import IonicShoppingToolSpec\n",
    "\n",
    "# optionally add you Ionic API Key\n",
    "# IonicShoppingToolSpec(api_key=\"<my Ionic API Key>\")\n",
    "ionic_tool = IonicShoppingToolSpec().to_tool_list()\n",
    "\n",
    "for tool in ionic_tool:\n",
    "    print(tool.metadata.name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80b4d128986d4a9",
   "metadata": {},
   "source": [
    "### Use Ionic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18bd589c4fd6ef44",
   "metadata": {},
   "outputs": [],
   "source": [
    "agent = FunctionAgent(\n",
    "    tools=ionic_tool,\n",
    "    llm=OpenAI(model=\"gpt-4.1\"),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aa6ee6bd0b1c8f22",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\n",
    "    await agent.run(\n",
    "        \"I'm looking for a 5k monitor can you find me 3 options between $600 and $1000\"\n",
    "    )\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
